package com.sunseaypw.springmvc.web.api;

import com.sunseaypw.springmvc.entity.User;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller  
public class Cont1 {
    @PostMapping(value = "/rest",
             consumes = "application/json;charset=UTF-8",
             produces = "application/json;charset=UTF-8")
    /*@RequestBody 注解则是将 HTTP 请求正文插入方法中，使用适合的 HttpMessageConverter 将请求体写入某个对象。
                   multipart/form-data, 不能处理
    @ResponseBody 表示该方法的返回结果直接写入 HTTP response body 中
    */
    @ResponseBody
    public String rest(@RequestBody User user) {
        return "{\"restSupport\":true}";
    }
    @GetMapping(value = "/rest2",
             consumes = "application/json;charset=UTF-8",
             produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String rest2() {
        return "{\"restSupport222\":true}";
    }

    @GetMapping(value = "/rest21",
             consumes = "application/json;charset=UTF-8",
             produces = "application/json;charset=UTF-8")
    @ResponseBody
    public User rest3() {
        User u=new User();
        u.setEmail("aa@qq.com");
        return u;
    }
}
